//
//  DoctorChatView.m
//  QuickCure1
//
//  Created by summer的Dad on 16/11/1.
//  Copyright © 2016年 maoge. All rights reserved.
//

#import "DoctorChatView.h"
@interface DoctorChatView () <UITextFieldDelegate>
@property(nonatomic,weak)UIImageView* imageView;
@property(nonatomic,weak)UIButton* ben;
@property(nonatomic,weak)UITextField*textField;




@end
@implementation DoctorChatView

/*
// Only override drawRect: if you perform custom drawing.
// An empty implementation adversely affects performance during animation.
- (void)drawRect:(CGRect)rect {
    // Drawing code
}
*/

- (instancetype)initWithFrame:(CGRect)frame
{
    
    if (self = [super initWithFrame:frame]) {
        
        
        [self setupUI];
        
    }
    
    return self;
    
}
#pragma mark
#pragma mark - 搭建界面
- (void)setupUI
{
    UIImageView* imageView = [[UIImageView alloc] initWithImage:[UIImage imageNamed:@"phone"]];
    
    [self addSubview:imageView];
    _imageView = imageView;
    //约束
    [imageView mas_makeConstraints:^(MASConstraintMaker *make) {
        make.leading.top.equalTo(self).offset(8);
        make.height.width.equalTo(@24);
        
    }];
    
    //右边的buttom
    UIButton* btn = [UIButton buttonWithType:0];
    [btn setTitle:@"发送" forState:UIControlStateNormal];
    [btn setTitleColor:[UIColor blackColor] forState:UIControlStateNormal];
    [btn addTarget:self action:@selector(clickButton:) forControlEvents:UIControlEventTouchUpInside];
    [self addSubview:btn];
    _ben = btn;
    //约束
    [btn mas_makeConstraints:^(MASConstraintMaker *make) {
        make.top.equalTo(self).offset(8);
        make.trailing.equalTo(self).offset(-8);
        make.height.equalTo(@24);
        make.width.equalTo(@50);
    }];
  
    
    
    
    UITextField* textField = [[UITextField alloc] init];
    textField.backgroundColor = [UIColor whiteColor];
    textField.borderStyle = UITextBorderStyleRoundedRect;
    textField.delegate = self;
    [self addSubview:textField];
    [textField addTarget:self
                   action:@selector(textFieldDidChange:)
         forControlEvents:UIControlEventEditingChanged];
    [textField mas_makeConstraints:^(MASConstraintMaker *make) {
        make.top.equalTo(self).offset(4);
        
        make.leading.equalTo(self.imageView.mas_trailing).offset(8);
        make.trailing.equalTo(self.ben.mas_leading).offset(-8);
    }];
    _textField = textField;
 
   
}
#pragma mark
#pragma mark - textfield监听事件
- (void) textFieldDidChange:(UITextField*) sender {
    
    // 文本内容
    NSInteger times = [sender.text integerValue];
    NSLog(@"%zd",times);
//    [_serviceNumList replaceObjectAtIndex:_servicePos withObject:[NSNumber numberWithInteger:times]];
//
//    // 总价
//    _totalPrice = (float)([_goodsList[_servicePos][@Price] floatValue]/100.0)*[[_serviceNumList objectAtIndex:_servicePos] integerValue];
//    [_totalPriceLabel setText:[NSString stringWithFormat:@%0.1f, _totalPrice]];
}


#pragma mark
#pragma mark - 按钮点击事件
-(void)clickButton:(UIButton *)sender{
    
    [sender setTitle:@"OK" forState: UIControlStateHighlighted];
    if ( [self.delegate respondsToSelector:@selector(doctorChatView:)] ) {
        [self.delegate doctorChatView:self];
    }
    
    
    [self endEditing:YES];
//    [sender resignFirstResponder];
    
}

@end
